package com.luoye.lj.pojo.vo;

import java.io.Serializable;

/**
 * 类标题： 前后端统一消息定义协议
 * 类说明： 服务端统一返回给客户端的响应体格式
 *
 * @author luo
 * @date 19:11 2018/10/17
 */
public class Message<T> implements Serializable {
    private boolean success;
    private  int  code;
    private  String  msg;
    private  T   data;

    public boolean isSuccess() {
        return success;
    }
    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public T getData() {
        return data;
    }

    public Message setData(T data) {
        this.data = data;
        return this;
    }

    public Message ok() {
        success=true;
        this.code=200;
        this.msg="成功";
        return this;
    }

    /**
     * 响应失败
     *
     * @param statusCode 状态码
     * @param statusMsg  状态描述
     * @return Message
     */
    public Message error(int statusCode, String statusMsg) {
        this.success=false;
        this.code=statusCode;
        this.msg=statusMsg;
        return this;
    }
}
